package com.colvir.infows.info.impl;

import com.colvir.infows.info.InfoPort;
import com.colvir.infows.info.types.GetAvailableProcessorsInfo;
import com.colvir.infows.info.types.GetFreeMemoryInfo;
import com.colvir.infows.info.types.GetInfoResponse;
import com.colvir.infows.info.types.GetJavaInfo;
import com.colvir.infows.info.types.GetOsInfo;
import com.colvir.infows.info.types.GetTotalMemoryInfo;

public class InfoPortImpl implements InfoPort {

	final String OS = System.getProperty("os.name").toLowerCase();
	final String JV = System.getProperty("java.version");  
	final String AP = String.valueOf(Runtime.getRuntime().availableProcessors());
          String FM = String.valueOf(Runtime.getRuntime().freeMemory());
          long maxMemory = Runtime.getRuntime().maxMemory();
          
	public GetInfoResponse getAvailableProcessors(GetAvailableProcessorsInfo request) {
		GetInfoResponse res  = new GetInfoResponse();
		res.setInfoResponse(AP);
		return res;
	}

	public GetInfoResponse getFreeMemory(GetFreeMemoryInfo request) {
		GetInfoResponse res  = new GetInfoResponse();
		res.setInfoResponse(FM);
		return res;
	}

	public GetInfoResponse getTotalMemory(GetTotalMemoryInfo request) {
		GetInfoResponse res  = new GetInfoResponse();
		res.setInfoResponse(maxMemory == Long.MAX_VALUE ? "no limit" : String.valueOf(maxMemory));
		return res;
	}

	public GetInfoResponse getJavaVersionInfo(GetJavaInfo request) {
		GetInfoResponse res  = new GetInfoResponse();
		res.setInfoResponse(JV);
		return res;
	}

	public GetInfoResponse getOsVersionInfo(GetOsInfo request) {
		GetInfoResponse res  = new GetInfoResponse();
		res.setInfoResponse(OS);
		return res;
	}

}
